import {call,put} from 'redux-saga/effects'
import axios from '../utils/request'
import { message} from 'antd';

export function * getShop({payload}){
    console.log(payload,'getshop-payload')
    const res=yield call(axios,{url:'/api/shop',method:'get',params:payload})
    console.log(res)
    if(res.code===1){
        yield put({
            type:'GET_SHOP',
            payload:res.data
        })
    }else{
        yield put({
            type:'GET_SHOP',
            payload:res.data
        })
    }
}

export function * edmitShop({payload}){  //编辑
    console.log(payload,'edmit-payload')
    const res=yield call(axios,{url:'/api/edmitshop',method:'put',data:payload})
    console.log(res)
    if(res.code===1){
        message.success(res.data.msg);
    }else{
        message.error(res.data.msg);
    }
}

export function * getDetail({payload}){//获取详情
    const res=yield call(axios,{url:`/api/shopdetail/${payload}`})
    console.log(res)
}

export function * delShop({payload}){//删除商品
    console.log(payload)
    const res=yield call(axios,{url:`/api/delshop/${payload}`,method:'delete'})
    console.log(res)
    if(res.code===1){
        message.success(res.data.msg);
    }else{
        message.error(res.data.msg);
    }
}

export function * addShop({payload}){//添加商品
    console.log(payload,'payload')
    const res=yield call(axios,{url:'/api/addshop',method:'post',data:payload})
    console.log(res)
    if(res.code===1){
        console.log(222)
        message.success(res.data.msg);
        window.location.href="/layout/goodsManage"
       
    }else{
        message.error(res.data.msg);
    } 
}